package com.bwie.es.exception;

import com.bwie.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@RestControllerAdvice
@Slf4j
public class MyExceptionHandle {

    @Autowired
    private HttpServletRequest request;


    @ExceptionHandler(ServiceException.class)
    public Result serviceExceptionHandle(ServiceException serviceException){
        log.error("发生业务异常,请求URI:{},异常信息如下:",
                request.getRequestURI(),
                serviceException.getMessage());
        return Result.error(serviceException.getMessage());
    }

}
